﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cofe.Core.Property
{

    public enum PropertyDefinitionComparationMode { Category, Property }
    public class PropertyDefinitionComparer : IEqualityComparer<IPropertyDefinitions>
    {

        public static PropertyDefinitionComparer CompareCategory
            = new PropertyDefinitionComparer() { ComparationMode = PropertyDefinitionComparationMode.Category };
        public static PropertyDefinitionComparer CompareProperty
            = new PropertyDefinitionComparer() { ComparationMode = PropertyDefinitionComparationMode.Property };

        private PropertyDefinitionComparer() { }
        public PropertyDefinitionComparationMode ComparationMode { get; private set; }        

        public bool Equals(IPropertyDefinitions x, IPropertyDefinitions y)
        {
            switch (ComparationMode)
            {
                case PropertyDefinitionComparationMode.Category:
                    return x.Category.Equals(y.Category);
                case PropertyDefinitionComparationMode.Property:
                    return x.GetSupportedProperties().Equals(y.GetSupportedProperties());
                default:
                    throw new NotSupportedException();
            }
        }

        public int GetHashCode(IPropertyDefinitions obj)
        {
            switch (ComparationMode)
            {
                case PropertyDefinitionComparationMode.Category:
                    return obj.Category.GetHashCode();
                case PropertyDefinitionComparationMode.Property:
                    return obj.GetSupportedProperties().GetHashCode();
                default:
                    throw new NotSupportedException();
            }
        }
    }
}
